package com.hashtable;

import java.util.HashMap;
import java.util.Map;

public class Solution06 {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        int res = 0;
        Map<Integer, Integer> map = new HashMap<>();
        for (int n1 : nums1) {
            for (int n2 : nums2) {
                int tmp = n1 + n2;
                if (map.containsKey(tmp)) map.put(tmp, map.get(tmp) + 1);
                else map.put(tmp, 1);
            }
        }

        for (int n3 : nums3) {
            for (int n4 : nums4) {
                int tmp = n3 + n4;
                if (map.containsKey(-tmp)) res += map.get(-tmp);
            }
        }
        return res;
    }
}
